<%@ page language="java" import="java.util.*,java.sql.*,connBean.*" pageEncoding="UTF-8"%>
<%@page import="com.jspsmart.upload.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>保存新闻信息判断</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <%
  SmartUpload upload =new SmartUpload();
  upload.initialize(pageContext);
  upload.setMaxFileSize(100000);
  upload.setAllowedFilesList("jpg,JPG,gif");
  upload.setDeniedFilesList("exe,bat,jsp,js,htm,html");
  upload.upload();
  upload.save("/upload");
  request.setCharacterEncoding("GBK");
  
  
  String b_name=upload.getRequest().getParameter("b_name");//菜名
  b_name=new String(b_name.getBytes("GBK"),"UTF-8");//把GBK转化为UTF-8

  
  String author=upload.getRequest().getParameter("author");//原料
  author=new String(author.getBytes("GBK"),"UTF-8");//把GBK转化为UTF-8
  int price=Integer.parseInt(upload.getRequest().getParameter("price"));//价格
  int type=Integer.parseInt(upload.getRequest().getParameter("type"));//类别
  String brief=upload.getRequest().getParameter("brief");//图书内容
  brief=new String(brief.getBytes("GBK"),"UTF-8");

  String filename=upload.getFiles().getFile(0).getFileName();//图片
  filename=new String(filename.getBytes("GBK"),"UTF-8");
   %>
   <%
 Class.forName("org.gjt.mm.mysql.Driver");//加载驱动程序类型
 String url="jdbc:mysql://localhost:3306/wldc?user=root&password=123&useUnicode=true&characterEncoding=utf-8";//设置连接数据库参数
 Connection conn=DriverManager.getConnection(url);//创建数据库连接
 /*
 Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);//发送SQL语句给数据库管理系统
 String sql="insert into news_a(newsclass,title,author,content,hits,pass,intime,photo,description) values('"+newsclass+"','"+title+"',"+author+",'"+content+"','"+intime+"','"+filename+"'+'"+description+"')";//定义插入SQL语句
 System.out.print(sql);
 int result=stmt.executeUpdate(sql);//执行SQL语句
 */
 String sql="insert into books(name,author,price1,brief,imgpath,type) values(?,?,?,?,?,?)";/*这个是增加操作*/
 
 PreparedStatement pstmt=conn.prepareStatement(sql);

 pstmt.setString(1,b_name);
 pstmt.setString(2,author);
 pstmt.setInt(3,price);
 pstmt.setString(4,brief);
 pstmt.setString(5,filename);
 pstmt.setInt(6,type);
 int result=pstmt.executeUpdate();
 if(result!=0){ 
 response.sendRedirect("bookManage.jsp");//执行插入成功跳转
 }else{
 response.sendRedirect("bookAdd.jsp");//执行插入失败跳转
 }
 %>
  </body>
</html>
